package jude.java.framework.thread;

import org.apache.commons.lang.StringUtils;

public abstract class Controller {

	protected Controlable target;
	private String[] commands;
	
	public Controller(Controlable target) {
		this.target = target;
		this.commands = target.getCommands();
	}
	
	public void startControl() {}
	
	protected void onCommand(String command) {
		if (StringUtils.isBlank(command))
			return;
		if (commands == null) {
			target.onCommand(-1, command);
			return;
		}
		String[] ss = StringUtils.split(command);
		for (int i = 0; i < commands.length; i++) {
			if (ss[0].equals(commands[i])) {
				target.onCommand(i, commands[i]);
				return;
			}
		}
	}
}
